package com.yueqian.service.impl;

import com.yueqian.dao.IRoleDao;
import com.yueqian.domain.Permission;
import com.yueqian.domain.Role;
import com.yueqian.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private IRoleDao roleDao;

    @Override
    public List<Role> findAll() throws Exception {
        List<Role> roleList = roleDao.findAll();
        return roleList;
    }

    @Override
    public void save(Role role) throws Exception {
        roleDao.save(role);
    }

    @Override
    public List<Permission> findRoleAndNoPermission(String roleId) throws Exception {
        List<Permission> permissionList = roleDao.findRoleAndNoPermission(roleId);
        return permissionList;
    }

    @Override
    public void addPermissionToRole(String roleId, String[] ids) throws Exception {
        for (String permissionId : ids) {
            roleDao.addPermissionToRole(roleId, permissionId);
        }
    }
}
